<?php
/**
 * Author:xsc
 * Time:2023/12/6 14:26
 */

namespace App\Repository;

use App\Models\OpenGoodsLockLog;

class OpenGoodsLockLogRepo extends BaseRepo
{

    /**
     * 新增/更新
     * @param array $data
     * @param int $id
     * @return int
     * Author:xsc
     * Time:2023/12/6 14:27
     */
    public function save(array $data, int $id = 0): int
    {
        if ($id) {
            return OpenGoodsLockLog::query()->where('id', $id)->update($data);
        } else {
            return OpenGoodsLockLog::query()->insertGetId($data);
        }
    }

    /**
     * 查询数据
     * @param array $params
     * @return array
     * Author:xsc
     * Time:2023/12/6 14:38
     */
    public function getData(array $params): array
    {
        $where = [];
        if (isset($params['serial_number'])) {
            $where[] = ['serial_number', '=', $params['serial_number']];
        }
        if (isset($params['lock_serial_number'])) {
            $where[] = ['lock_serial_number', '=', $params['lock_serial_number']];
        }
        if (isset($params['platform_id'])) {
            $where[] = ['platform_id', '=', $params['platform_id']];
        }
        if (isset($params['goods_id'])) {
            $where[] = ['goods_id', '=', $params['goods_id']];
        }

        return OpenGoodsLockLog::query()->where($where)->get()->toArray();
    }

}
